package com.Service;

import com.Dao.GoodsDao;
import com.POJO.Goods;
import com.Service.Imp.GoodsServiceImp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class GoodsService extends ServiceImpl<GoodsDao, Goods> implements GoodsServiceImp {
    @Autowired
    GoodsDao goodsDao;
    public List<Goods> findCategoryGoods(int categoryId){
        QueryWrapper<Goods> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("category_id",categoryId);
        return goodsDao.selectList(queryWrapper);
    }
    public int  updataCategoryGoods(String categoryId,int goodsId,String goodsName,String goodsContent,String money){
        Goods goods=new Goods();
        UpdateWrapper<Goods> updateWrapper=new UpdateWrapper<>();

        updateWrapper.set("category_id",categoryId);
        updateWrapper.set("money",new BigDecimal(money));
        updateWrapper.set("goods_content",goodsContent);

        updateWrapper.set("goods_name",goodsName);
        updateWrapper.eq("goods_id",goodsId);
        return goodsDao.update(goods,updateWrapper);
    }
    public int  delCategoryGoods(int goodsId){
        QueryWrapper<Goods> updateWrapper=new QueryWrapper<>();
        updateWrapper.eq("goods_id",goodsId);
        return goodsDao.delete(updateWrapper);
    }
    public int  addCategoryGoods(int categoryId,String goodsName,String goodsContent,String money){
        Goods goods=new Goods();
        goods.setGoodsContent(goodsContent);
        goods.setGoodsName(goodsName);
        goods.setCategoryId(categoryId);
        goods.setMoney(new BigDecimal(money));
        return goodsDao.insert(goods);
    }

}
